package com.pxst.init.bank;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.pxst.bank.entity.SysAvailableBankEntity;
import com.pxst.bank.service.SysAvailableBankService;
import com.pxst.enums.RedisKeyEnums;
import com.pxst.utils.RedisUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 初始化支持qr的银行code
 * 
 * @author yangxy
 * @version 创建时间：2023年9月8日 上午11:19:34
 */
@Slf4j
@Component
public class QrBankInit implements CommandLineRunner {
	@Autowired
	private RedisUtils redisUtils;
	@Autowired
	private SysAvailableBankService availableBankService;

	@Override
	public void run(String... args) throws Exception {
		// TODO Auto-generated method stub
		List<SysAvailableBankEntity> list = availableBankService.list(new LambdaQueryWrapper<SysAvailableBankEntity>()
				.eq(SysAvailableBankEntity::getIsQr, 1).eq(SysAvailableBankEntity::getStatus, 1));
		List<String> qrBankCodeList = list.stream().map(SysAvailableBankEntity::getBankCode).collect(Collectors.toList());
		if(!qrBankCodeList.isEmpty()) {
			redisUtils.set(RedisKeyEnums.QR_BANKCODE.key, qrBankCodeList);
		}
		log.info("初始化支持qr的银行code成功");
	}

}
